package com.sz.icbc.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sz.icbc.service.AccountService;
import com.sz.icbc.util.RSAUtils;
import com.sz.icbc.vo.Transfer;
import com.sz.icbc.vo.TransferInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ICBCBankController {

    @Autowired
    AccountService accountService;
    private  String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJfeEQl9KDsOHoDF3C4kQXTaAw836B7XIRcO1EEFJWHWYcdz2KyZRrMk8Kj42n1ds3f3KUeOyJpffiUa0I/Irc3wbw0fspu9Qq3IRCbl8D/E1GaZ73WMQzV6OdMC6cK6OjGm+5r/VWywWYSe9N0e1D5dIfUqA0OK5ngyneEj2jlfAgMBAAECgYBmC8S88ImI7RrYApvJsXj+UMP/hNyHZJ0Khl9fdVrCHDDFufUdPT1BgQ/pKpZ96OmAMedd+vaWrJXxzsvX4cvO7XbuTE4bh/XqTJzs1ZragDsfZy9Dpamh3RSOzJDUxGlj6173RzzdzvdVQrYeZEUBgUNy2OZWii9bjP+g5ElpuQJBAM7j4t9a7CFESTeg778sMySsamAZdKL89Hs1l21LlrQ27h+B++etH5wLsMwVgrWIabbRwXL9jbVk4Vky0vfbX70CQQC76pvsUJg+zdU3vUeWnYqcXjyukxrrmpuHOy5CePQNO2CpN1KodbyetMGcRBjRUqIu0kGhQxcdzoYfU+tJajFLAkEAhUqezUX34crr3RIrxCAG5zbJ5hYgZi3QmVzCraDIfFzzd4s4L2ADgHartiCZsLktWqKzHpGq7dYLtXsgHp3QhQJADxosy9IyWiHKt/8TSMyCfkyojdMuv66eP0EHV7pGyuVxwEe88eL8dLjMMpXadMAyXpbxRVeR/QhDCTOCXlUVfwJAbN6BrK+Q/EXgRzmDXDcoZVImxUzk2rAN0Ja3rybXzJhbEF7GuK2iN4X3WRM6rz6naxZli/0DGMqRI2aW8Zlvhw==";
    @PostMapping("/icbc/transfer")
    public String getAcc(@RequestParam("secretKey") String secretKey) throws Exception {
        System.out.println(privateKey);
        String str = RSAUtils.decrypt(secretKey,RSAUtils.getPrivateKey(privateKey));
        System.out.println(str);
        TransferInfoVO transfer = JSON.parseObject(str,TransferInfoVO.class); //JSON.parseObject(str,Transfer.class);
        System.out.println(transfer);
        return accountService.modifyAccount(transfer);

    }
    @PostMapping("/icbc/acc")
    public String  getAcc(TransferInfoVO transfer){
        System.out.println(transfer);
        return accountService.modifyAccount(transfer);
    }
}
